package org.endy.leisure.diaTracker.repository

import org.endy.leisure.diaTracker.entity.question.Question
import org.springframework.data.jpa.repository.JpaRepository
import org.springframework.data.jpa.repository.JpaSpecificationExecutor
import org.springframework.data.jpa.repository.Query
import org.springframework.stereotype.Repository

@Repository
interface QuestionRepository : JpaRepository<Question, Long>, JpaSpecificationExecutor<Question> {

    /**
     * 通过用户的ID查询提问
     */
    fun findQuestionByUserId(userId: Long): List<Question>

    /**
     * 查询所有还未被回答的问题
     */
    @Query("SELECT q FROM Question q WHERE q.answer IS NULL")
    fun findNoAnswerQuestions(): List<Question>

}